/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import com.feiyue.helper.AnimationTabHost;

public class BookCityTabActivity extends TabActivity implements
		View.OnTouchListener, GestureDetector.OnGestureListener {
	private static final String CATEGORY = "category";
	private static final String FREE = "free";
	private static final String NEWEST = "newest";
	private static final String SEARCH = "search";
	public static int currenttab = -1;
	private TextView category_bookstore;
	private LinearLayout category_bookstore_linearlayout;
	private Context context;
	private int firstTabIndex = -1;
	private int fourthTabIndex = -1;
	private TextView free_bookstore;
	private LinearLayout free_bookstore_linearlayout;
	private GestureDetector mGestureDetector;
	private int minVelocity = 150;
	private TextView newest_bookstore;
	private LinearLayout newest_bookstore_linearlayout;
	private TextView search_bookstore;
	private LinearLayout search_bookstore_linearlayout;
	private int secondTabIndex = -1;
	AnimationTabHost tabHost;
	private int thirdTabIndex = -1;
	private int verticalMinDistance = 200;

	public boolean dispatchTouchEvent(MotionEvent paramMotionEvent) {
		if (Build.VERSION.SDK_INT >= 14) {
			if (!(this.mGestureDetector.onTouchEvent(paramMotionEvent)))
				return super.dispatchTouchEvent(paramMotionEvent);
			return true;
		}
		return super.dispatchTouchEvent(paramMotionEvent);
	}

	protected void go2this(String s)
    {
        if (!s.equals("newest")) {
            if (s.equals("category"))
            {
                newest_bookstore_linearlayout.setBackgroundDrawable(null);
                category_bookstore_linearlayout.setBackgroundResource(R.drawable.bookcity_tab_item_underline);
                search_bookstore_linearlayout.setBackgroundDrawable(null);
                free_bookstore_linearlayout.setBackgroundDrawable(null);
            } else
            if (s.equals("search"))
            {
                newest_bookstore_linearlayout.setBackgroundDrawable(null);
                category_bookstore_linearlayout.setBackgroundDrawable(null);
                search_bookstore_linearlayout.setBackgroundResource(R.drawable.bookcity_tab_item_underline);
                free_bookstore_linearlayout.setBackgroundDrawable(null);
            } else
            if (s.equals("free"))
            {
                newest_bookstore_linearlayout.setBackgroundDrawable(null);
                category_bookstore_linearlayout.setBackgroundDrawable(null);
                search_bookstore_linearlayout.setBackgroundDrawable(null);
                free_bookstore_linearlayout.setBackgroundResource(R.drawable.bookcity_tab_item_underline);
            }
        } else {
            newest_bookstore_linearlayout.setBackgroundResource(R.drawable.bookcity_tab_item_underline);
            category_bookstore_linearlayout.setBackgroundDrawable(null);
            search_bookstore_linearlayout.setBackgroundDrawable(null);
            free_bookstore_linearlayout.setBackgroundDrawable(null);
        }
    }

	protected void initialBookstore() {
		Intent localIntent1 = new Intent(this.context, BookRankActivity.class);
		TabHost.TabSpec localTabSpec1 = this.tabHost
				.newTabSpec("newest_bookstore")
				.setIndicator("newest_bookstore",
						getResources().getDrawable(R.drawable.tab_bg))
				.setContent(localIntent1);
		this.tabHost.addTab(localTabSpec1);
		this.firstTabIndex = 0;
		Intent localIntent2 = new Intent(this.context,
				BookCategoryActivity.class);
		TabHost.TabSpec localTabSpec2 = this.tabHost
				.newTabSpec("category_bookstore")
				.setIndicator("category_bookstore",
						getResources().getDrawable(R.drawable.tab_bg))
				.setContent(localIntent2);
		this.tabHost.addTab(localTabSpec2);
		this.secondTabIndex = 1;
		Intent localIntent3 = new Intent(this.context, BookSearchActivity.class);
		TabHost.TabSpec localTabSpec3 = this.tabHost
				.newTabSpec("search_bookstore")
				.setIndicator("search_bookstore",
						getResources().getDrawable(R.drawable.tab_bg))
				.setContent(localIntent3);
		this.tabHost.addTab(localTabSpec3);
		this.thirdTabIndex = 2;
		Intent localIntent4 = new Intent(this.context, FreeActivity.class);
		TabHost.TabSpec localTabSpec4 = this.tabHost
				.newTabSpec("free_bookstore")
				.setIndicator("free_bookstore",
						getResources().getDrawable(R.drawable.tab_bg))
				.setContent(localIntent4);
		this.tabHost.addTab(localTabSpec4);
		this.fourthTabIndex = 3;
		currenttab = this.tabHost.getCurrentTab();
	}

	public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.context = getApplicationContext();
    setContentView(R.layout.tab_top);
    this.tabHost = ((AnimationTabHost)findViewById(android.R.id.tabhost));
    this.mGestureDetector = new GestureDetector(this);
    LinearLayout localLinearLayout = (LinearLayout)findViewById(R.id.tab_top);
    localLinearLayout.setOnTouchListener(this);
    localLinearLayout.setLongClickable(true);
    initialBookstore();
    this.newest_bookstore_linearlayout = ((LinearLayout)findViewById(R.id.newest_bookstore_linearlayout));
    this.newest_bookstore = ((TextView)findViewById(R.id.newest_bookstore));
    this.newest_bookstore.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          BookCityTabActivity.this.tabHost.setCurrentTab(BookCityTabActivity.this.firstTabIndex);
          BookCityTabActivity.this.go2this("newest");
          BookCityTabActivity.currenttab = BookCityTabActivity.this.tabHost.getCurrentTab();
        }
      });
    this.category_bookstore_linearlayout = ((LinearLayout)findViewById(R.id.category_bookstore_linearlayout));
    this.category_bookstore = ((TextView)findViewById(R.id.category_bookstore));
    this.category_bookstore.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          BookCityTabActivity.this.tabHost.setCurrentTab(BookCityTabActivity.this.secondTabIndex);
          BookCityTabActivity.this.go2this("category");
          BookCityTabActivity.currenttab = BookCityTabActivity.this.tabHost.getCurrentTab();
        }
      });
    this.search_bookstore_linearlayout = ((LinearLayout)findViewById(R.id.search_bookstore_linearlayout));
    this.search_bookstore = ((TextView)findViewById(R.id.search_bookstore));
    this.search_bookstore.setOnClickListener( new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          BookCityTabActivity.this.tabHost.setCurrentTab(BookCityTabActivity.this.thirdTabIndex);
          BookCityTabActivity.this.go2this("search");
          BookCityTabActivity.currenttab = BookCityTabActivity.this.tabHost.getCurrentTab();
        }
      });
    this.free_bookstore_linearlayout = ((LinearLayout)findViewById(R.id.free_bookstore_linearlayout));
    this.free_bookstore = ((TextView)findViewById(R.id.free_bookstore));
    this.free_bookstore.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          BookCityTabActivity.this.tabHost.setCurrentTab(BookCityTabActivity.this.fourthTabIndex);
          BookCityTabActivity.this.go2this("free");
          BookCityTabActivity.currenttab = BookCityTabActivity.this.tabHost.getCurrentTab();
        }
      });
    go2this("newest");
    this.tabHost.setOpenAnimation(true);
  }

	public boolean onDown(MotionEvent paramMotionEvent) {
		return false;
	}

	public boolean onFling(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
    {
        boolean flag;
        float f2;
        flag = true;
        f2 = Math.abs(motionevent.getX() - motionevent1.getX()) / Math.abs(motionevent.getY() - motionevent1.getY());
        if (motionevent.getX() - motionevent1.getX() <= 0.0F || (double)f2 - 2.5D <= 0.0D) {
        	if (motionevent.getX() - motionevent1.getX() < 0.0F && (double)f2 - 2.5D > 0.0D)
            {
                if (tabHost.getCurrentTab() == fourthTabIndex)
                {
                    tabHost.setCurrentTab(thirdTabIndex);
                    go2this("search");
                    currenttab = tabHost.getCurrentTab();
                } else if (tabHost.getCurrentTab() == thirdTabIndex)
                {
                    tabHost.setCurrentTab(secondTabIndex);
                    go2this("category");
                    currenttab = tabHost.getCurrentTab();
                } else if (tabHost.getCurrentTab() == secondTabIndex)
                {
                    tabHost.setCurrentTab(firstTabIndex);
                    go2this("newest");
                    currenttab = tabHost.getCurrentTab();
                }
            }
            flag = false;
        } else {
        	if (tabHost.getCurrentTab() != firstTabIndex) {
        		if (tabHost.getCurrentTab() == secondTabIndex)
                {
                    tabHost.setCurrentTab(thirdTabIndex);
                    go2this("search");
                    currenttab = tabHost.getCurrentTab();
                    overridePendingTransition(0x7f04000a, 0x7f04000d);
                } else
                if (tabHost.getCurrentTab() == thirdTabIndex)
                {
                    tabHost.setCurrentTab(fourthTabIndex);
                    go2this("free");
                    currenttab = tabHost.getCurrentTab();
                    overridePendingTransition(0x7f04000a, 0x7f04000d);
                }
        	} else {
        		tabHost.setCurrentTab(secondTabIndex);
                go2this("category");
                currenttab = tabHost.getCurrentTab();
                overridePendingTransition(0x7f04000a, 0x7f04000d);
        	}
        }
        
        return flag;
    }

	public void onLongPress(MotionEvent paramMotionEvent) {
	}

	public boolean onScroll(MotionEvent paramMotionEvent1,
			MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2) {
		return false;
	}

	public void onShowPress(MotionEvent paramMotionEvent) {
	}

	public boolean onSingleTapUp(MotionEvent paramMotionEvent) {
		return false;
	}

	public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
		if (Build.VERSION.SDK_INT >= 14)
			return this.mGestureDetector.onTouchEvent(paramMotionEvent);
		return super.onTouchEvent(paramMotionEvent);
	}
}